<!DOCTYPE html>
<html>
 {{{ html.header(out) }}}
<body>

{{{ html.navbar(out,"/web/settings") }}}

<div class="container">
  <div class="row">
   
  <div class="col-sm-5">
  <form id="x" action="/TQAE/configFile" method="GET">
  
  <div class="mb-3">
    <label for="cf" class="form-label">Configuration file</label>
    <input type="text" class="form-control" name="cf" id="cf" value="{{{out(EM.readConfigFile or "")}}}" aria-describedby=2"cfHelp">
    <div id="cfHelp" class="form-text">File with initial settings</div>
  </div>
  
  <button type="submit" class="btn btn-primary" formaction="/TQAE/readConfigFile">Read</button>
  <button type="submit" class="btn btn-primary"formaction="/TQAE/saveConfigFile">Save</button>
  <hr>
  
{{{

      local function iString(cfp,name,value,descr)
        out([[<div class="mb-3">
              <label for="user" class="form-label">%s</label>
              <input type="text" class="form-control" name="%s" id="%s" value="%s" aria-describedby="userHelp">
              <div id="userHelp" class="form-text">%s</div>
              </div>]],name,cfp,cfp,value,descr)
      end

      local function iBoolean(cfp,name,value,descr)
        out([[<div class="form-check form-switch">
              <label class="form-check-label" for="%s">%s</label>
              <input class="form-check-input" type="checkbox" role="switch" name="%s" id="%s" aria-describedby="%sH" %s>
              <div id="%sH" class="form-text">%s</div>
              </div>]],cfp,name,cfp,cfp,cfp,EM.cfg[cfp] and "checked" or "",cfp,descr)
      end
      
      local configs = EM.configFileValues 
      for _,c in pairs(EM.configParams) do
        if c.type=='bool' then iBoolean(c.cfp,c.name,configs[c.cfp]==true,c.descr)
        else iString(c.cfp,c.name,configs[c.cfp] or "",c.descr) end
      end
}}}
  </div>
  
  <div class="col-sm-1"></div>
  
  <div class="col-sm-4">
  <label class="form-label">Debug flags</label>
{{{
    local flags = EM.configFileValues.debug or {}
    local function switch(name,descr)
       out([[
         <div class="form-check form-switch"">
         <input class="form-check-input" name="%s" type="checkbox" id="%sF" %s aria-describedby="%sH">
         <label class="form-check-label" for="%sF">%s</label>
         <div id="%sH" class="form-text">%s</div>
         
         </div>]],name,name,flags[name]==true and "checked" or "",name,name,name,name,EM.LOG.descr[name] or "Undocumented")
    end
    local res = {}
    for flag,_ in pairs(EM.LOG.flags) do res[#res+1]=flag end
    table.sort(res)
    for _,flag in pairs(res) do
      switch(flag,"debug."..flag)
    end
}}}
</div>

</form>
</div>
</div>

{{{ html.footer(out) }}}
</body>
</html>